package com.fudan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fudan.dto.entities.Question;
import com.fudan.dto.entities.Room;
import com.fudan.service.QuestionServiceImpl;
import com.fudan.service.RoomServiceImpl;


@RestController
@RequestMapping("/question")
@CrossOrigin(origins = "http://localhost:4200")
public class QuestionController {
	
	@Autowired
	private QuestionServiceImpl questionService;
	

    @RequestMapping(value="/like",method = RequestMethod.POST)
    @ResponseBody
	public String like(Integer questionId, Integer userId){
		System.out.println("questionId "+questionId+" userId " + userId);
		questionService.like(questionId, userId);
		
		return "success";
	}
	
	@RequestMapping(value="/createQuestion",method = RequestMethod.POST)
    @ResponseBody
	public String createQuestion(@RequestParam("roomId") Integer roomId, @RequestParam("question") String questionStr, @RequestParam("userId")Integer userId){
		Question question =questionService.createQuestion(roomId, questionStr, userId);
		
		return "success";
	}

	


}
